package com.example.pictureview;

import android.graphics.drawable.AnimationDrawable;
import androidx.appcompat.app.AppCompatActivity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

public class bofang extends AppCompatActivity {
    private ImageView mImg;
    private AnimationDrawable mAd;
    Button zt;
    private MediaPlayer mediaPlayer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.bofang);
        mediaPlayer = MediaPlayer.create(bofang.this, R.raw.candy_wind);
        mImg = (ImageView) findViewById(R.id.imageView1);
        mImg.setBackgroundResource(R.drawable.my_frameanimation);
        mAd = (AnimationDrawable) bofang.this.mImg.getBackground();
        mAd.start();
        mediaPlayer.start();

        zt=findViewById(R.id.zt);
        zt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(mediaPlayer.isPlaying()){
                    mediaPlayer.pause();//暂停播放
                    ((Button)v).setText("继续");
                    mAd.stop();
                }else {
                    mediaPlayer.start();//继续播放
                    mAd.start();
                    ((Button)v).setText("暂停");
                }
            }
        });
    }
}
